Skip to content

Deprecate iter_named_leaf_modules and iter_named_quantizable_modules #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 9, 2025

Conversation

kylesayrs
Copy link
Contributor

@kylesayrs kylesayrs commented Jul 7, 2025

Purpose

  • Refactor module targeting to be cleaner and easier to maintain
  • Support skipping TransformBase modules

Prerequisites

Changes

  • Deprecated iter_named_leaf_modules and iter_named_quantizable_modules
    • These functions are near copies of each other
    • These functions don't actually have any runtime savings over simple model.modules(). Infact, they're likely significantly slower
    • These functions hard code against "observer" module names and are difficult to extend to other modules like Transforms
  • Add UntargetableModule class
class UntargetableModule(torch.nn.Module):
    """
    Abstract base class for modules which are not a part of the the model definition.
    `torch.nn.Module`s which inherit from this class will not be targeted by configs
    This is typically used to skip apply configs to `Observers` and `Transforms`
    """

    pass
  • Observer and TransformBase inherit from this class

TODO

  • Add skip in transforms apply

Testing

kylesayrs added 5 commits July 7, 2025 11:56
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
@kylesayrs kylesayrs changed the title Remove iter_named_leaf_modules and iter_named_quantizable_modules Deprecate iter_named_leaf_modules and iter_named_quantizable_modules Jul 8, 2025
@kylesayrs kylesayrs marked this pull request as ready for review July 8, 2025 04:04
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
Copy link
Contributor

@brian-dellabetta brian-dellabetta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

discussed with @kylesayrs that mapping all iter_named_leaf_modules, regardless of whether include_attn/include_children are False or True, to torch built-in .named_modules() method, should not affect overall behavior

Copy link
Member

@rahul-tuli rahul-tuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahul-tuli rahul-tuli merged commit 40fa3c5 into main Jul 9, 2025
1 of 2 checks passed
@rahul-tuli rahul-tuli deleted the kylesayrs/genericize-quant-apply branch July 9, 2025 17:12
dsikka pushed a commit to vllm-project/llm-compressor that referenced this pull request Jul 9, 2025
…es` (#1628)

## Purpose ##
* Refactor module targeting to be cleaner and easier to maintain
* Support skipping `TransformBase` modules

## Prerequisites ##
* neuralmagic/compressed-tensors#381

## Changes ##
* Remove all uses of `iter_named_leaf_modules` and
`iter_named_quantizable_modules`
* Make `Observer` inherit from `InternalModule`

## Testing ##
*
https://github.com/neuralmagic/llm-compressor-testing/actions/runs/16123598340
✅

---------

Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants